package com.zls.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zls.pojo.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface TProducterMapper extends BaseMapper<TProducter> {
    @Results(id = "tproducterMap", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "isactive", property = "isactive"),
            @Result(column = "username", property = "username"),
            @Result(column = "phone", property = "phone"),
            @Result(column = "wechat", property = "wechat"),
            @Result(column = "usercard", property = "usercard"),
            @Result(column = "createdate", property = "createdate"),
            @Result(column = "sys_user_id", property = "sysUserId"),
            @Result(column = "producer_type_id", property = "producerTypeId"),
            @Result(column = "password", property = "password"),
            @Result(column = "farm_id", property = "farmId"),
            @Result(column = "openid", property = "openid"),
            @Result(column = "sys_user_id", property = "sysUser", javaType = SysUser.class, one =
            @One(select = "com.zls.mapper.SysUserMapper.selectById", fetchType = FetchType.EAGER)),
            @Result(column = "producer_type_id", property = "tProducerType", javaType = TProducerType.class, one =
            @One(select = "com.zls.mapper.TProducerTypeMapper.selectById", fetchType = FetchType.EAGER)),
            @Result(column = "farm_id", property = "tFarm", javaType = TFarm.class, one =
            @One(select = "com.zls.mapper.TFarmMapper.selectById", fetchType = FetchType.EAGER)),
    })
    @Select("<script>" +
            "select * from t_producter where 1=1" +
            "<if test='queryString!=null'> and username like concat( '%',#{queryString},'%')" +
            "limit #{currentPage},#{pageSize}</if>" +
            "<if test='queryString==null'>limit #{currentPage},#{pageSize}</if> "+
            "</script>")
    List<TProducter> findPage(@Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize, @Param("queryString") String queryString);

    //查询总记录数
    @Select("<script>" +
            "select count(*) from t_producter where 1 =1" +
            "<if test='queryString!=null'> and username like concat( '%',#{queryString},'%') </if>" +
            "</script>")
    Long count(String queryString);

    @ResultMap("tproducterMap")
    @Select("select * from t_producter where id=#{id}")
    TProducter selectId(int id);

    @ResultMap("tproducterMap")
    @Select("select * from t_producter where phone=#{phone} and password=#{password} ")
    TProducter login(TProducter tProducter);
}
